<?php
    /*
    ** Zabbix
    ** Copyright (C) 2001-2015 Zabbix SIA
    **
    ** This program is free software; you can redistribute it and/or modify
    ** it under the terms of the GNU General Public License as published by
    ** the Free Software Foundation; either version 2 of the License, or
    ** (at your option) any later version.
    **
    ** This program is distributed in the hope that it will be useful,
    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    ** GNU General Public License for more details.
    **
    ** You should have received a copy of the GNU General Public License
    ** along with this program; if not, write to the Free Software
    ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    **/

    require_once dirname(__FILE__) . '/include/config.inc.php';
    require_once dirname(__FILE__) . '/include/hosts.inc.php';
    require_once dirname(__FILE__) . '/include/reports.inc.php';

    $page['title'] = _('Zabbix zatree');
    $page['file'] = 'zatree.php';
    $page['hist_arg'] = array('mode', 'groupid', 'hostid', 'tpl_triggerid');
    $page['scripts'] = array('class.calendar.js');
    $page['type'] = detect_page_type(PAGE_TYPE_HTML);
    require_once dirname(__FILE__) . '/include/page_header.php';

    $zatree_widget = new CWidget(null,"zatree_iframe");
    $zatree_widget->addPageHeader("Zatree",get_icon('fullscreen',array('fullscreen'=>$_REQUEST['fullscreen'])));
    $zatree_iframe_left = new CIFrame("zatree/left.php","100%","100%","auto","zatree_iframe_left");
    $zatree_iframe_right = new CIFrame("zatree/graph.php","100%","100%","auto","zatree_iframe_right");
    $zatree_iframe_left->setAttribute("name","leftFrame");
    $zatree_iframe_left->setAttribute("id","leftFrame");
    $zatree_iframe_right->setAttribute("name","rightFrame");
    $zatree_iframe_right->setAttribute("id","rightFrame");
    $zatree_widget->addItem(new CDiv($zatree_iframe_left,"iframe","zatree_left"));
    $zatree_widget->addItem(new CDiv(new CDiv(null,"line"),"iframe","resizeDiv"));
    $zatree_widget->addItem(new CDiv($zatree_iframe_right,"iframe","zatree_right"));
    $zatree_widget->show();

    $resizeJs = "
        var $ = jQuery;
        var \$gtree_widget = $('#resizeDiv').parent();
        var \$resizeDiv = $('#resizeDiv'); //jQury 对象
        var resizeDiv = $('#resizeDiv')[0]; //dom 对象
        var _drag = false;
        \$resizeDiv.on('mousedown',function(e){
            _drag = true;
            var disX = e.clientX;
            var glw = $('#zatree_left').width();
            var grw = $('#zatree_right').width();
            \$gtree_widget.on('mousemove',function(e1){
                if(_drag){
                    var iT = e1.clientX - disX;
                    $('#zatree_left').width(glw + iT);
                    $('#zatree_right').width(grw - iT);
                }
                return false;
            });

            \$gtree_widget.on('mouseup',function() {
                \$gtree_widget.unbind('mousemove mouseup');
                //\$gtree_widget.unbind('mouseup');
                //resizeDiv.releaseCapture && resizeDiv.releaseCapture();
                this.releaseCapture && this.releaseCapture();
                _drag = false;
                return false;
            });

            \$gtree_widget.on('mouseleave',function() {
                \$gtree_widget.unbind('mousemove mouseup');
                _drag = false;
                //resizeDiv.releaseCapture && resizeDiv.releaseCapture();
                this.releaseCapture && this.releaseCapture();
                return false;
            });

            this.setCapture && this.setCapture();
            return false;
        });


    ";
    insert_js($resizeJs,true);


    require_once dirname(__FILE__) . '/include/page_footer.php';
